<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use Kkokk\Poster\Facades\Html;
use Knp\Snappy\Pdf as Pdf2;
class Pdf extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';


    //scl 很多的那个
    public function detail1()
    {

        $id = $this->request->get('id');
        $info = (new \app\admin\model\SubjectRecord())->where('id',$id)->with(['subject'])->find();
        if (empty($info)){
            echo 'failed';
            exit;
        }
        $info = $info->toArray();
        $info['report'] = json_decode($info['report'],true);
        $this->view->assign('info',$info);
        return $this->view->fetch();
    }
    
    public function detail3()
    {
        $id = $this->request->get('id');
        $info = (new \app\admin\model\SubjectRecord())->where('id',$id)->with(['subject'])->find();

        if (empty($info)){
            echo 'failed';
            exit;
        }
        $info = $info->toArray();
        $info['report'] = json_decode($info['report'],true);
        $this->view->assign('info',$info);
        return $this->view->fetch();
    }
    public function detail5()
    {
        $id = $this->request->get('id');
        $info = (new \app\admin\model\SubjectRecord())->where('id',$id)->with(['subject'])->find();
        if (empty($info)){
            echo 'failed';
            exit;
        }
        $info = $info->toArray();
        $info['report'] = json_decode($info['report'],true);
        $this->view->assign('info',$info);
        return $this->view->fetch();
    }

    public function pdf()
    {


        $html = file_get_contents('https://qwuser.wshare.club/index/pdf/detail3.html');
        $htmlObj = Html::load($html)->transparent()->render();

// 流文件
//        $blob = $htmlObj->getImageBlob();
// 文件地址
        $file = $htmlObj->getFilePath();

//        dump($blob);
        dump($file);
    }

    public function pdf2()
    {

        $pdf = new Pdf2('/usr/local/bin/wkhtmltopdf');//设置一下存储pdf的路径和文件名(我将他存储在public 目录下
        $path=time().'.pdf';//执行一下插件
        $pdf->generate('https://qwuser.wshare.club/index/pdf/detail1.html', $path);

        dump($path);

    }
}
